﻿
@{
    ViewBag.Title = "CouponEidt";
}

@using YouWei.Infrastructure.Entity;
@model Coupon
@{
    ViewBag.Title = "优惠券编辑";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form id="editForm" class="form ">
                <div class="form-group">
                    <label>券码</label>
                    <input type="text" class="form-control" name="CouponCode" id="CouponCode" value="@Model.CouponCode" />
                </div>
                <div class="form-group">
                    <label>类型</label>
                    <select id="CouponType" name="CouponType" class="form-control">
                        <option value="-1">全部</option>
                        <option value="1">洗车</option>
                        <option value="2">礼品</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>面值</label>
                    <input type="text" class="form-control" name="CouponPrice" id="CouponPrice" value="@Model.CouponPrice" />
                </div>
                <div class="form-group">
                    <label>渠道</label>
                    <input type="text" class="form-control" name="Channel" id="Channel" value="@Model.Channel" />
                </div>
                <div class="form-group">
                    <label>折扣（两位小数）</label>
                    <input type="text" class="form-control" name="Discount" id="Discount" value="@Model.Discount" />
                </div>
                <div class="form-group">
                    <label>批次</label>
                    <input type="text" class="form-control" name="Batch" id="Batch" value="@Model.Batch" />
                </div>
                <div class="form-group">
                    <button type="button" class="btn btn-success btn-sm" id="btnSave">保存</button>
                </div>
            </form>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script type="text/javascript">
        $(document).ready(function () {
            //分类
            var id = @Model.CouponID;
            if (id > 0) {
                var type = "@Model.CouponType";
                $("#CouponType").val(type);
            }
            $("#btnSave").on("click", function () {
                save();
            });
        });
        //保存
        function save() {
            var fdata = $("#editForm").serializeJson();
                var id = "@Model.CouponID";
                BMCW.ajax({
                    url: "@Url.Action("CouponSave", "Coupon")?id=" + id,
                    type: "POST",
                    data: fdata,
                    dataType: "json",
                        success: function (data) {
                            if (data.status == 0) {
                                BMCW.alert(data.message);
                                setTimeout(function () {
                                    window.location.reload();
                                }, 2000);
                            } else {
                                BMCW.alert(data.message);
                            }
                        }
                    });
        }
    </script>
}